-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Report Scheduler] Documentation of Scheduling Logic #31134
[Report Scheduler] Documentation of Scheduling Logic #31134
Conversation
6d31342
to
aef3e07
Compare
PR #31134: Size comparison from 19e202e to aef3e07 Increases (31 builds for bl702, cc13x4_26x4, cyw30739, efr32, esp32, k32w, nrfconnect, telink)
Decreases (10 builds for bl602, bl702, bl702l, linux)
Full report (72 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, psoc6, qpg, telink)
|
aef3e07
to
1d1639f
Compare
PR #31134: Size comparison from ad98820 to 1d1639f Increases (29 builds for bl702, bl702l, cc13x4_26x4, cyw30739, esp32, k32w, qpg, telink)
Decreases (11 builds for bl602, bl702, bl702l, linux)
Full report (72 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, psoc6, qpg, telink)
|
4bbd090
to
60c8876
Compare
60c8876
to
512ffa2
Compare
Co-authored-by: Junior Martinez <[email protected]>
512ffa2
to
03286a0
Compare
PR #31134: Size comparison from c7f8ec9 to 03286a0 Increases (30 builds for bl702, cc13x4_26x4, cyw30739, esp32, k32w, nrfconnect, telink)
Decreases (12 builds for bl602, bl702, bl702l, efr32, linux)
Full report (72 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, psoc6, qpg, telink)
|
* | ||
* It inherits the ReadHandler::Observer class to be notified of reportability changes in the ReadHandlers. | ||
* It inherits the ICDStateObserver class to allow the implementation to generate reports based on the changes in ICD devices state, | ||
* such as going from idle to active and vice-versa. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`such as going from idle to active mode and vice-versa.
* | ||
* @brief This class is in charge of determining when a ReadHandler is reportable depending on the monotonic timestamp of the | ||
* system and the intervals of the ReadHandler. It inherits the TimerContext class to allow it to be used as a context for a | ||
* TimerDelegate so the TimerDelegate can call the TimerFired method when the timer expires. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TimerDelegate so that the TimerDelegate can call the TimerFired method when the timer expires.
* | ||
* The Logic to determine if a ReadHandler is reportable at a precise timestamp is as follows: | ||
* 1: The ReadHandler is in the CanStartReporting state | ||
* 2: The minimal interval since last report has elapsed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The minimal interval since the last report has elapsed
* The Logic to determine if a ReadHandler is reportable at a precise timestamp is as follows: | ||
* 1: The ReadHandler is in the CanStartReporting state | ||
* 2: The minimal interval since last report has elapsed | ||
* 3: The maximal interval since last report has elapsed or the ReadHandler is dirty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The maximal interval since the last report has elapsed or the ReadHandler is dirty
* | ||
* @brief This class extends ReportScheduler and provides a scheduling logic for the CHIP Interaction Model Reporting Engine. | ||
* | ||
* It is reponsible for implementing the ReadHandler and ICD observers callbacks to the Scheduler can take actions whenever a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
callbacks to the Scheduler
sentence seems off here.
* un-necessary since the ReadHandler will call MoveToState(HandlerState::CanStartReporting);, which will call | ||
* OnBecameReportable() and schedule the report. | ||
* | ||
* @note This method sets a now Timestamp that is used to calculate the next report timeout. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does a now Timestamp
mean set a timestamp to now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it means a timestamp to the moment of the call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about "This method captures the current timestamp, which can later be used to ... "?
* | ||
* @brief This class extends ReportSchedulerImpl and overrides it's scheduling logic. | ||
* | ||
* It only overrides Observers method where the scheduling logic make it necessary, the others are kept as is. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setence seems odd
* ## Scheduling Logic | ||
* | ||
* This class implements a scheduling logic that aims to make all ReadHandlers report at the same time when possible. | ||
* The goal is to minimize the different times a device wakes up to report, and thus this aims to schedule all reports at the latest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minimize the number of times a device wakes up to report
* The logic also aims to minimize the impact on the responsivity of the device. | ||
* | ||
* The scheduling logic is as follows: | ||
* - The CalculateNextReportTimeout is called by the same ReadHandler Observer callbacks than the non-synchronized implementation: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
callbacks as the non-synchronized implementation:
* * Are Reportable (this prevents a ReadHandler that is not reportable to hold the report of all the others) | ||
* TODO: Assess if we want to keep this behavior or simply let the min interval be the earliest min interval to prevent cases | ||
* where a ReadHandler with a dirty path but a very high min interval blocks all reports | ||
* - If no ReadHandlerNode matches min interval the criteria, the next min interval is set to current timestamp. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
matches the min interval
* | ||
* Additionnal flags have been provided for specific use cases: | ||
* | ||
* CanbeSynced: Mechanism to allow the ReadHandler to emit a report if another readHandler is ReportableNow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CanBeSynced, no?
* Additionnal flags have been provided for specific use cases: | ||
* | ||
* CanbeSynced: Mechanism to allow the ReadHandler to emit a report if another readHandler is ReportableNow. | ||
* This flag can substitute the maximal interval condition or the dirty condition. It is currently only used by the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this means "This flag can replace the maximal interval condition or the dirty condition"?
But this is actually really hard to follow. First we say "we are reportable if all three of these things are true", and then we later say "oh, actually, some of those can be false if some of these other things are true".
What this documentation should talk about is conceptually what things might keep us from being reportable and for each one which sets of things might be able to remove that impediment.
As I see, it there are three impediments:
- The ReadHandler is not in CanStartReporting state. The only way to remove this impediment is to be in that state, right?
- The ReadHandler has reported too recently. This can be removed by enough time passing or EngineRunScheduled being set by a timer firing, etc, right?
- The ReadHandler has no need to report. This can be removed by either being dirty (hence needing to report), or getting to the max interval (likewise), or CanBeSynced being true and another ReadHandler needing to report, in which case we might as well also report.
Do those descriptions make sense? I think recasting this documentation in terms sort of like those would be a lot clearer....
* This flag can substitute the maximal interval condition or the dirty condition. It is currently only used by the | ||
* SynchronizedReportScheduler. | ||
* | ||
* EngineRunScheduled: Mechanism to ensure that the reporting engine will see the ReadHandler as reportable if a timer fires. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bringing us back to: why is this called EngineRunScheduled? Is that the really important thing? Or is the important thing "we think we have reached our min interval, even though the clock disagrees"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It means this: "This ReadHandler's timer fired, thus ScheduleReport was called, and we want the Report Engine to see the ReadHandler as reportable on the next run, regardless of what the clock thinks"
This could be renamed "TimerFired" flag if this seems more clear. Will update the description in my ongoing re-write, I can also update the name if you think it would make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about ForceReportableOnNextEngineRun if that's what it means?
* | ||
* EngineRunScheduled: Mechanism to ensure that the reporting engine will see the ReadHandler as reportable if a timer fires. | ||
* This flag can substitute the minimal interval condition or the maximal interval condition. The goal is to allow for | ||
* reporting when timers fire earlier than the minimal timestamp du to mechanism such as NTP clock adjustments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/du/due/, but this whole comment might end up changing a bunch.
* This class implements a scheduling logic that calculates the next report timeout based on the current system timestamp, the state | ||
* of the ReadHandlers associated with the scheduler nodes and the min and max intervals of the ReadHandlers. | ||
* | ||
* @note This class mimics the original scheduling in which the ReadHandlers would schedule themselves. The key difference is that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think anyone cares that this "mimics" code that is now gone. It would be better instead to clearly describe the algorithm this class is aiming to implement.
* While looping, it checks if any handler is reportable now. If not, we recalculate the next report timeout and reschedule the | ||
* report. | ||
* | ||
* If a Readhangler is reportable now, an engine run is scheduled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is a "Readhangler"?
* | ||
* If a report is already scheduled, cancel it and schedule a new one. | ||
* | ||
* @param[in] timeout The timeout to schedule the report. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The delay before the report will happen, no?
* @note Since this method is called after the OnSubscriptionReportSent callback, to avoid an endless reporting loop, Nodes with | ||
* the IsEngineRunScheduled flag set are ignored when finding if the Scheduler should report at min, max or now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is much better as comments go, but I wish it explained why not ignoring them would lead to "an endless reporting loop"....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loop description added.
* @note Since this method is called after the OnSubscriptionReportSent callback, to avoid an endless reporting loop, Nodes with | ||
* the IsEngineRunScheduled flag set are ignored when finding if the Scheduler should report at min, max or now. | ||
* | ||
* @note If a ReadHandler's report is Chunked, the IsEngineRunScheduled is ignored since we do want to keep rescheduling the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"chunked" is not a proper noun.
* @note Since this method is called after the OnSubscriptionReportSent callback, to avoid an endless reporting loop, Nodes with | ||
* the IsEngineRunScheduled flag set are ignored when finding if the Scheduler should report at min, max or now. | ||
* | ||
* @note If a ReadHandler's report is Chunked, the IsEngineRunScheduled is ignored since we do want to keep rescheduling the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part of the documentation is confusing. Is this discussing an exception to the "avoid an endless loop" bit above? If so, it would be clearer to just describe what situations we want to reschedule in and what situations not, without this weird "we do X, except no, in case Y we do Z" structure.
This PR clarifies the logic behind the ReportScheduler base class and its two implementation:
ReportSchedulerImpl and SynchronizedReportSchedulerImpl